import $ from "jquery";
import "../../scss/modifyPassword.scss";
import oldcom from "../utils/oldcommon/common";
require("../utils/remove_ad");
require("../utils/oldcommon/layer");

var modify = {
    password:function () {
        var oldPassword = $.trim($('#oldPassword').val());
        var newPassword = $.trim($('#newPassword').val());
        var surePassword = $.trim($('#surePassword').val());
        console.log($("#modify_password").serialize());
        if((newPassword.length < 6) || (surePassword.length < 6) || (oldPassword < 6)){
            oldcom.alert('密码至少6位。'); return;
        }else if( newPassword === surePassword){

            $.ajax({
                type: "POST",
                url: "/user/sureModify",
                data:{
                    "oldPassword":oldPassword,
                    "newPassword":newPassword
                },
                dataType: "json",
                success: function(data){
                    console.log(data);
                    if(data.status){
                        layer.open({
                            content:'修改成功。'
                            ,btn: '确定'
                            ,yes:function(){
                                setTimeout(function () {
                                    if(data.data.returnUri){
                                        window.location.href = data.data.returnUri;
                                    }else{
                                        window.location.href = '/center';
                                    }
                                }, 1000);
                            }
                        });
                    }else{
                        layer.open({
                            content:data.msg
                            ,btn: '确定'
                        });
                    }
                }
            });
        }else{
            oldcom.alert('两次输入密码不一致'); return;
        }
    }
};
$(".sure_modify").click(function () {
    modify.password();
})
